import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';

void main() {
  // group -> setUpAll -> tearDownAll -> test.
  // flutter drive --target=test_driver/listApp.dart
  group('Long List App', () {
    // 连接
    FlutterDriver driver;
    setUpAll(() async {
      driver = await FlutterDriver.connect();
    });

    tearDownAll(() async {
      if (driver != null) {
        driver.close();
      }
    });

    test('verifies the list contains a specific item', () async {
      // 定义Finders
      final listFinder = find.byValueKey('long_list');
      final itemFinder = find.byValueKey('item_50_text');

      // 定义动作线
      final timeline = await driver.traceAction(() async {
        await driver.scrollUntilVisible(listFinder, itemFinder,
            dyScroll: -300.0);
        print(await driver.getText(itemFinder));
        expect(await driver.getText(itemFinder), 'Item 50');
      });

      // 保存结果到磁盘
      final summary = new TimelineSummary.summarize(timeline);
      // 保存summary到文件
      summary.writeSummaryToFile('scrolling_summary', pretty: true);
      // 保存timeline到文件
      summary.writeTimelineToFile('scrolling_timeline', pretty: true);
    });
  });
}
